package eat;



    public class Man extends Thread {

        private String name;

        private long time;

        private Plate p;

        public Man(String name, long time, Plate p) {
            this.name = name;
            this.time = time;
            this.p = p;
        }

        @Override
        public void run() {
            int num = 0;
            while (true) {
                synchronized (this.p) {
                    if (this.p.getJz() == 0) {
                        break;
                    }
                    num++;
                    this.p.setJiaozi(this.p.getJz() - 1);
                    System.out.println(this.name + "吃了" + num + "个饺子！");
                }
                try {
                    Thread.sleep(time);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }



